home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PsL Monthly 1993 December
/
PSL Monthly Shareware CD-ROM (December 1993).iso
/
prgmming
/
dos
/
pascal
/
virtmem.exe
/
VIRTUMEM.DOC
< prev
next >
Wrap
Text File
|
1992-10-08
|
14KB
|
297 lines
VirtuMem: Virtual memory system.
---------------------------------
Written by Wayne Knorr for Techsonix Marketing.
Suite 630, Atrium II
840 6th Ave S.W.
Calgary, Alberta
Canada T2P 3E5
Phone: (403) 269-6007
Fax: (403) 265-8484
CompuServe ID: 72470,1217
These units may be used and distributed freely and without guilt.
To become a registered user, thus receiving the source code (Turbo
Pascal 6.0) , full documentation with technical overview, updates, and
technical support, send $18.00, to Techsonix Marketing at the
above address, along with the completed registration form found in the file
REGISTER.FRM.
VirtuMem is also available for Amiga systems (with C source code).
--------------------
Brief overview:
---------------
VirtuMem is a memory management unit that replaces the traditional heap.
Each allocation, deallocation, and dynamic memory reference is achieved
through a call to one of the VirtuMem procedures or functions. When there
is no more traditional heap space left, the system (optionally) starts
using expanded memory that is available. When this is also used up, a
memory image is created on secondary storage automatically. The parts of
memory that are not commonly used are swapped out of memory, making room for
those that are commonly used. Typically more than 99.5% of all memory
accesses are found in memory. Up to 4 Gigabytes of information can
theoretically be handled (for those who found a really good sale on hard
disks.)
Use:
----
Virtual structures can replace any or all dynamically allocated structures.
These include (but are not limited to) dynamically allocated arrays, records,
and objects. This conversion is not automatic, so some work must be done
in order to switch existing programs so they may use VirtuMem. (Turbo Vision
applications are particularly painful since Turbo Vision has its own
memory allocation scheme.) Every variable that would normally be declared
as a pointer type is now declared as a virtual pointer, which is a longint.
These dynamic structures are accessed through the VirtuMem routines.
The three core routines of VirtuMem are called ANew, R, and Depossess. In
addition to these, three more, OpenBook, CloseBook, and Unstay are needed
to make the system run properly. The declarations of these, as they appear
in the interface section of the source code, is found in the file
VIRTUMEM.INT. An example program which uses all of these calls is found
in the file VIRTUEXM.PAS.
ANew allocates a new virtual block and returns a virtual pointer (LongInt)
to it. It takes the size of the structure as a parameter.
Depossess frees the space allocated by ANew. This space may then be used
by subsequent calls to ANew, keeping the size of the virtual memory small.
This takes as parameters the pointer to be freed and the size of the
structure (which should be the same as that passed to ANew).
R is used to access a virtumem block. This is the interface between the
VirtuMem system and the normal memory system. R takes a virtual pointer
as its parameter and returns a Turbo Pascal pointer to the structure
in real memory. This pointer to real memory is guaranteed to be valid until
the next call to a VirtuMem routine. After a call to VirtuMem, however,
there is a chance that the structure may have been kicked out of real memory
to make room for another structure. The user may have to use type casting
to change the returned value from type Pointer to the individual pointer
type that is required.
R takes a second parameter, called Mucky. Mucky can take one of three values
defined in the VirtuMem unit. These are called Clen, Dirt, and Stay, and
give the system an indication of what is going to happen to the data being
accessed.
Clen indicates that the structure being accessed is being read only. After
one read, the fact that the structure is in memory is ignored. If it later
becomes necessary for that structure to be swapped out to make room in real
memory for a new structure, it is merely overwritten. The old structure is
not written back to disk since it is assumed that no changes to it were made.
That is, the copy of the structure that is already on disk is assumed to
still be correct. Typically Clen would be used in a comparison, when
the structure is passed to a procedure as a value parameter, or on the
left hand side of an assignment statement.
Dirt indicates that the structure being accessed will in some way be
modified. When the Virtual Memory access uses the dirt parameter, VirtuMem
ensures that the structure is rewritten to disk before it is swapped out
of real memory. Typically Dirt would be used on the left hand side of an
assignment statement.
Stay is used to force the structure to remain in real memory indefinitely
(until a call is made to the procedure Unstay). This is necessary in cases
where Turbo Pascal implicitely references a pointer. Normally, from one
virtual memory call to the next, the virtual pointer remains the same
but the real memory location of a structure may change. There are, however,
cases where the real memory pointer must also remain the same for some time.
It is in these cases that the Stay parameter is used. The two most common
cases where this is necessary are in a "With" statement and when passing
a structure in virtual memory by reference. It is important to keep in
mind that memory taken by a "stayed" virtual memory call is no longer
available to be used by the rest of the system. The stay parameter should
also be used in single line complex calculations where several calls are
made to VirtuMem and the results are stored internally.
Unstay frees a structure that was forced to stay in real memory by using
R with "Stay" as the second parameter. It takes a virtual pointer as
a parameter which should be the same virtual pointer as was the first
parameter in the call to R.
OpenBook initializes the virtual memory system. It must be called before
any other VirtuMem call. A boolean flag is required as a parameter. This
is set to TRUE to suppress the use of EMS, and FALSE to allow the use of
EMS.
CloseBook ends the use of EMS, freeing used memory and closing used files.
Advantages of Using VirtuMem:
-----------------------------
VirtuMem allows virtually unlimited dynamic space. It also gives a seamless
interface to expanded memory. The VirtuMem system also does a minimal amount
of error checking that may make debugging easier. For example, it prints
a warning if an attempt is made to reference a structure through a null
pointer. Also, when pointers are freed they are automatically set back to
null.
Disadvantages of Using VirtuMem:
--------------------------------
Each pointer reference must be surrounded by a call to the routine R. This
makes programming more cumbersome and also slows down execution time. All
pointers are of the same type, so compile time type checking is ineffective.
Real memory locations of structures can only be found via calls to R or
a complex analysis of the data structures. Some structures may not even
be in memory, but only on disk. This makes tracing through dynamic data
structures, such as linked lists, via a debugger very difficult.
Error Messages:
---------------
VirtuMem may produce several error messages which may be cryptic to the user.
Below is an explanation of what the common ones mean.
-Failed mapping.
A call to the Expanded Memory Manager, attempting to map an expanded
memory page into real memory has failed. This normally should not happen.
-ENTRY.
The amount of virtual memory being used is greater than the amount that
VirtuMem has been compiled for by default. Use less or recompile the
VirtuMem unit with the compiler directive VERYLARGE set.
-Conventional static memory overflow. Data will be contorted.
-Conventional stay count is n.
-Static memory overflow. Data will be contorted.
These all indicate that there is no real memory left to swap virtual